﻿/*
	Class			PixelBox
	
	Description		------
					
	History			------
	
	To Do			------
*/

package tv.digitalfx
{
	import tv.digitalfx.Pixel;
	import flash.display.Sprite;
	
	public class PixelBox extends Sprite
	{
		public  static const RECTANGLE:String	= "rectangle";
		public  static const HORIZONTAL:String	= "horizontal";
		public  static const VERTICAL:String	= "vertical";
		
		private const PIXEL_WIDTH:Number 		= 2;
		private var   _tempWidth:Number;
		private var   _tempHeight:Number;
		private var   _color:uint;
		
		
		public function PixelBox ($width:Number = 100, $height:Number = 100, $color:uint = 0xffffffff, $type:String = RECTANGLE)
		{
			_tempWidth   = Math.round ($width / PIXEL_WIDTH);
			_tempHeight  = Math.round ($height / PIXEL_WIDTH);
			_color       = $color;
			
			if ($type == RECTANGLE || $type == HORIZONTAL)
			{
				drawHorizontalPixels ();
			}
			
			if ($type == RECTANGLE || $type == VERTICAL)
			{
				drawVerticalPixels   ();
			}
		}
		
		
		private function drawHorizontalPixels ():void
		{
			for (var X:int = 0; X < _tempWidth; X++)
			{
				var topPixel:Pixel			= new Pixel (_color, PIXEL_WIDTH);
				topPixel.y				= 0;
				
				var bottomPixel:Pixel		= new Pixel (_color, PIXEL_WIDTH);
				bottomPixel.y				= (_tempHeight - 1) * PIXEL_WIDTH;
				
				topPixel.x = bottomPixel.x	= X * PIXEL_WIDTH;
				
				addChild					(topPixel);
				addChild					(bottomPixel);
			}
		}
		
		
		private function drawVerticalPixels ():void
		{
			for (var Y:int = 0; Y < _tempHeight; Y++)
			{
				var leftPixel:Pixel			= new Pixel (_color, PIXEL_WIDTH);
				leftPixel.x				= 0;
				
				var rightPixel:Pixel		= new Pixel (_color, PIXEL_WIDTH);
				rightPixel.x				= (_tempWidth - 1) * PIXEL_WIDTH;
				
				leftPixel.y = rightPixel.y	= Y * PIXEL_WIDTH;
				
				addChild					(leftPixel);
				addChild					(rightPixel);
			}
		}
		
	}
}